#!/bin/sh

site=""

while [ "$#" -gt "0" ]; do
	site="$1"
	shift
done

if [ -z "$site" ]; then
	echo "No site specified" >&2
	exit 1
fi

pass "$site" > "/tmp/pass_site"
printf "\n\n%s\n" "$(openssl rand -base64 400 | tr -d "\n")" >> "/tmp/pass_site"
st -e nvim "/tmp/pass_site"

choice="$(printf "yes\nno" | dmenu -p "save changes? ")"

if [ "$choice" = "yes" ]; then
	echo "message-info saving" > "$QUTE_FIFO"
	pass add -f -m "$site" < "/tmp/pass_site"
	echo "message-info saved" > "$QUTE_FIFO"
else
	echo "message-info 'operation aborted by the user'" > "$QUTE_FIFO"
fi
